home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
Window.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-24
|
6KB
|
350 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "Window.h"
#include "Class.h"
#include "Error.h"
#include "WindowPort.h"
#include "WindowSystem.h"
#include "ObjectTable.h"
#include "ClassManager.h"
#include "Storage.h"
#include "View.h"
#include "Document.h"
#include "Env.h"
#include "Look.h"
#include "Buttons.h"
#include "String.h"
#include "MenuBar.h"
extern bool testwindow;
extern char *gProgPath;
Token gToken;
Window *gWindow;
//---- Window ----------------------------------------------------------------
NewMetaImpl(Window,Clipper, (TB(active), TP(manager), TP(portDesc), TP(icon)));
Window::Window(Manager *m, Point e, WindowFlags f, VObject *in, char *title)
: Clipper(0, gPoint_1)
{
Init(m, in, eWinStandard, eCrsBoldArrow, f, title, e);
}
Window::Window(Manager *m, VObject *vp, WindowType wt, WindowFlags f, Point e,
char *title)
: Clipper(0, gPoint_1)
{
Init(m, vp, wt, eCrsBoldArrow, f, title, e);
}
void Window::Init(Manager *eh, VObject *in, WindowType wt, GrCursor curs,
WindowFlags wf, char *t, Point e)
{
wtype= wt;
wflags= wf;
manager= eh;
ResetFlag(eVObjOpen);
cursor= curs;
bgcolor= gInkNone;
bgcolor= gLook->GetBackgroundColor();
SetDeleteVop(TRUE);
inner= in;
contentRect.extent= e;
VObject *v= gWindowSystem->MakeWindowBorder(wtype, inner, t, wf & eWinBlock, wf & eWinFixed);
Add(v);
}
Window::~Window()
{
if (vop != inner) {
if (deleteVop)
SafeDelete(inner);
deleteVop= TRUE;
}
if (icon) {
Window *tmp= icon;
icon= 0;
delete tmp;
}
if (portDesc) {
portDesc->Remove(); // mark as free
portDesc= 0;
}
}
void Window::ExtentChanged(VObject*)
{
// SetExtent(Max(GetMinSize().Extent(), GetExtent()));
SetExtent(GetMinSize().Extent());
}
Command *Window::DoMenuCommand(int cmd)
{
return Clipper::DoMenuCommand(cmd);
}
EvtHandler *Window::GetNextHandler()
{
return manager;
}
void Window::SetNextManager(Manager *m)
{
manager= m;
}
void Window::InvalidateRect(Rectangle r)
{
MakePort()->InvalidateRect(r);
}
void Window::SetExtent(Point e)
{
MakePort()->SetExtent(e);
}
void Window::SetOrigin(Point at)
{
VObject::SetOrigin(gPoint0);
MakePort()->SetOrigin(GetRect().origin+at);
}
void Window::Focus()
{
if (IsOpen() && portDesc) {
GrSetPort(portDesc);
GrInitClip();
GrClipFurther(contentRect);
GrTranslate(Offset());
}
}
void Window::FocusNotify(bool f)
{
gWindow= this;
if (portDesc == 0)
return;
GrSetPort(portDesc);
if (active != f) {
active= f;
if (manager)
manager->SetActive(active);
}
}
void Window::InputNotify(Token *t)
{
gWindow= this;
if (portDesc == 0)
return;
GrSetPort(portDesc);
gToken= *t;
if (t->Code == eEvtEnter || t->Code == eEvtExit) {
bool f= t->Code == eEvtEnter;
if (f != active) {
active= f;
if (manager)
manager->SetActive(active);
}
} else if (t->IsKey() && t->Flags == (eFlgShiftKey|eFlgCntlKey|eFlgMetaKey)) {
switch (t->MapToAscii()) {
case 'q': // emergency exit
Close();
break;
case 't':
gSystem->Abort();
break;
case 'p':
Print();
break;
case 's':
gClassManager->InstanceStatistics();
break;
case 'i':
gClassManager->InstanceStatistics(TRUE);
break;
case 'l':
ToggleLook();
{
vop->SetExtent(GetExtent());
vop->SetOrigin(gPoint0);
ForceRedraw();
UpdateEvent();
}
break;
case 'e':
Error("InputNotify", "forced invocation of ErrorHandler");
break;
case 'm':
Storage::Statistics();
break;
}
return;
}
if (manager && (gToken.IsKey() || gToken.IsFunctionKey() || gToken.IsCursorKey())) {
manager->InputKbd(gToken);
} else {
PerformCommand(DispatchEvents(gToken.Pos, gToken, this));
}
UpdateEvent();
}
void Window::OpenNotify(Point e)
{
if (testwindow) fprintf(stderr, "OpenNotify: %d %d\n", e.x, e.y);
if (portDesc) {
gWindow= this;
GrSetPort(portDesc);
if (! IsOpen())
Clipper::Open(TRUE);
VObject::SetExtent(e);
if (vop)
vop->SetContentRect(Rectangle(gPoint0, e), TRUE);
UpdateEvent();
}
}
void Window::CloseNotify()
{
if (IsOpen()) {
if (testwindow) fprintf(stderr, "CloseNotify\n");
Clipper::Open(FALSE);
}
}
void Window::ResizeNotify(Point e)
{
if (IsOpen())
if (testwindow) fprintf(stderr, "ResizeNotify: %d %d\n", e.x, e.y);
}
GrCursor Window::GetCursor(Point)
{
return cursor;
}
class WindowPort *Window::MakePort()
{
if (portDesc == 0)
portDesc= gWindowSystem->MakeWindow(this, wtype, cursor);
return portDesc;
}
void Window::Open(bool mode)
{
if (mode) // open
OpenAt(GetRect().origin);
else if (portDesc)
portDesc->Hide();
}
void Window::OpenAt(Point p, VObject *fp, bool resize, bool block)
{
WindowPort *fatherport= 0;
if (IsOpen()) {
Top();
return;
}
if (fp) {
Window *w= fp->GetWindow();
if (w)
fatherport= (WindowPort*) (w->portDesc);
p= fp->GetPortPoint(p);
}
GrSetPort(MakePort());
if (resize)
contentRect= gPoint0;
Point e= Max(GetMinSize().Extent(), GetExtent());
if (manager)
p-= manager->GetInitialPos(e);
portDesc->Show(fatherport, Rectangle(p, e), block || (wflags & eWinBlock));
if (fatherport)
GrSetPort(fatherport);
}
void Window::Iconize()
{
if (icon == 0)
icon= MakeIcon();
if (icon)
icon->icon= this;
MakePort()->Iconize();
}
Window *Window::MakeIcon()
{
if (manager) {
VObject *vop= manager->DoMakeIconContent();
char *label= BaseName(gProgPath);
if (vop)
return new Window(manager, vop, eWinIcon, eWinFixed, Point(64), label);
}
return 0;
}
Rectangle Window::ScreenRect()
{
return WindowSystem::screenRect - GetRect().origin;
}
void Window::ReadEvent(Token &t, int timeout, bool overread)
{
MakePort()->GetEvent(&gToken, timeout, overread);
t= gToken;
}
Rectangle Window::GetRect()
{
return MakePort()->GetRect();
}
void Window::PushBackEvent(Token t)
{
MakePort()->PushEvent(t);
}
void Window::Top()
{
MakePort()->Top();
}
void Window::Bottom()
{
MakePort()->Bottom();
}
void Window::Bell(long d)
{
MakePort()->Bell(d);
}
void Window::SetMousePos(Point p)
{
MakePort()->SetMousePos(p);
}
void Window::Grab(bool g, bool fs)
{
MakePort()->Grab(g, fs);
}
void Window::SetTitle(char *tit)
{
MakePort()->SetTitle(tit);
}